<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.11.3.min.js"></script>
    <title>My JSP 'name1.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript">
	/* $(function(){
		//给username派发一个失去焦点事件 发送ajax请求
		$("input[name='username']").blur(function(){
			//获取输入的值
			var $value=$(this).val();
			//alert($value);
			
			 $.get("userservlet","username="+$value,function(d){
				//alert(d);
				  if(d==true){
					$("#span").html("<font color='green'>用户名可以使用</font>");
				}else{
					$("#span").html("<font color='red'>用户名已被使用</font>");
				}  
			},"json"); 
		});
	}) */
	$(function(){
		$("#name").blur(function(){
			//alert($(this).val());
			 $.post("userservlet",{name:$(this).val()},function(d){
				if(d==true){
					$("#span").html("<font color='green'>用户名可以使用</font>");
				}else{
					$("#span").html("<font color='red'>用户名已被使用</font>");
				} 
			},"json");
		});
		
	})
</script>
  </head>
  
  <body>
     <form action=# >
    用户名：<input type="text" name="username" id="name" >
    <span id="span"></span><br/>
    <input type="submit" value="提交" id="sub">
    </form>
  </body>
</html>
